package com.cms.dao;

import java.util.List;

import org.springframework.stereotype.Component;

import com.cms.base.HibernateDAOImpl;
import com.cms.base.Pagination;
import com.cms.entity.Channel;

@Component(value="channelDao")
public class ChannelDao extends HibernateDAOImpl<Channel> {
	
	
	public Pagination<Channel> queryAllChannels(Channel channel, int firstResult, int maxResults){
		String hql = "select c from Channel c where 1=1 ";
		List<Channel> list = this.getSession()
				.createQuery(hql)
				.setFirstResult(firstResult)
				.setMaxResults(maxResults)
				.list();
		
		String countHql = "select count(c.id) from Channel c where 1=1 ";
		int total = ((Long)(this.getSession().createQuery(countHql).uniqueResult())).intValue();
		
		Pagination<Channel> pagination = new Pagination<Channel>();
		pagination.setData(list);
		pagination.setTotal(total);
		return pagination;
	}
	
	public List<Channel> queryChannels(Channel channel){
		String hql = "select c from Channel c where 1=1 ";
		List<Channel> list = this.getSession()
				.createQuery(hql)
				.list();
		return list;
	}
	
}
